package com.hua.api.core.framework.util;

import com.hua.api.core.framework.util.exception.ApiError;
import lombok.Data;

import java.io.Serializable;

@Data
@SuppressWarnings("all")
public class Result<T> implements Serializable {

    private T data;


    private int code=200;
    /**
     * 通信描述
     */
    private String message = "";

    /**
     * 通过静态方法获取实例
     */
    public static <T> Result<T> of(T data) {
        return new Result<>(data);
    }

    public static  Result success() {
        return new Result<>("success");
    }


    public static Result error(ApiError error){
        return new Result(error);
    }

    @Deprecated
    public Result() {

    }

    private Result(ApiError error){
        this.code=error.getErrorCode();
        this.message=error.getHint();
    }

    private Result(T data) {
        this.data = data;
    }

    private Result(T data, boolean flag) {
        this.data = data;
        this.code = 200;
    }

    private Result(T data, boolean flag, String msg) {
        this.data = data;
        this.code = 200;
    }

}
